class Photo < ActiveRecord::Base
  file_column :image, :magick=>{
    :versions=>{"thumb"=>"100x100","normal"=>"600x450"}
  }
  validates_presence_of :image
  
  belongs_to :album, :counter_cache=>true
  has_many :comments, :dependent=>:destroy,:as=>:resource

  def previous_in(album)
    Photo.find(:first,:conditions=>["created_at <? and album_id=?",
        self.created_at,album.id],
      :order=>'created_at DESC')
  end

  def next_in(album)
    Photo.find(:first,:conditions=>["created_at >? and album_id=?", 
        self.created_at, album.id],
      :order=>'created_at ASC')
  end
 
end
